package com.example.smartcity.Service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.example.smartcity.Entity.Banner;
import com.example.smartcity.Entity.News;
import com.example.smartcity.Mappers.BannerMapper;
import com.example.smartcity.Mappers.NewsMapper;
import com.example.smartcity.Service.BannerService;
import com.example.smartcity.utils.MybatisUtils;
import com.google.gson.Gson;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("BannerService")
public class BannerServiceImpl implements BannerService {
    public String getAllBanner(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        BannerMapper bannerMapper =sqlSession.getMapper(BannerMapper.class);
        List<Banner> banners = bannerMapper.findAll();
        sqlSession.close();
        Gson gson = new Gson();
        String jsonString = gson.toJson(banners);
        System.out.println(jsonString);
        JSONObject map = new JSONObject();
        map.put("total",banners.size());
        map.put("rows",banners);
        map.put("code",200);
        map.put("msg","查询成功");
        System.out.println(JSONObject.toJSONString(map));
        return JSONObject.toJSONString(map);
    }
}
